package result

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Result struct {
	Code    int         `json:"code"`    //业务状态码
	Message string      `json:"message"` //提示信息
	Data    interface{} `json:"data"`    // 响应数据
}

func Response(ctx *gin.Context, httpStatus int, code int, message string, data interface{}) {
	ctx.JSON(httpStatus, gin.H{"code": code, "message": message, "data": data})
}

func Success(ctx *gin.Context, message string) {
	Response(ctx, 200, 200, message, nil)
}

func SuccessData(ctx *gin.Context, message string, data interface{}) {
	Response(ctx, 200, 200, message, data)
}

func Error(ctx *gin.Context, code int, message string) {
	Response(ctx, 200, code, message, nil)
}

func ErrorData(ctx *gin.Context, code int, message string, data interface{}) {
	Response(ctx, 500, code, message, data)
}

func PageRsult(ctx *gin.Context, rows interface{}, total int64) {
	ctx.JSON(http.StatusOK, gin.H{"code": 200, "message": "分页查询成功", "rows": rows, "total": total})
}
